/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('dms-yaochi-portal', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CheckUserAuthResponseBody = {
  code?: string(name='Code', example='BizError'),
  data?: string(name='Data', example='{
    "authState": 1,
    "lastAuthDate": "2024-01-26T09:01:41.000+00:00"
  }'),
  message?: string(name='Message', example='BizError'),
  requestId?: string(name='RequestId', example='A651D79E-798B-5AC5-84CD-712F2744CF3C'),
  success?: boolean(name='Success', example='true'),
}

model CheckUserAuthResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: CheckUserAuthResponseBody(name='body'),
}

async function checkUserAuthWithOptions(runtime: Util.RuntimeOptions): CheckUserAuthResponse {
  var req = new OpenApi.OpenApiRequest{};
  var params = new OpenApi.Params{
    action = 'CheckUserAuth',
    version = '2023-02-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function checkUserAuth(): CheckUserAuthResponse {
  var runtime = new Util.RuntimeOptions{};
  return checkUserAuthWithOptions(runtime);
}

model ListResourcesByTagRequest {
  pageNumber?: int32(name='PageNumber', example='1'),
  pageSize?: int32(name='PageSize', example='30'),
  tagKeys?: [ string ](name='TagKeys'),
  tagValues?: [ string ](name='TagValues'),
}

model ListResourcesByTagResponseBody = {
  data?: string(name='Data', example='[
    "rm-xxxxxx",
    "rm-xxxxxx"
  ]'),
  pageNumber?: int32(name='PageNumber', example='1'),
  pageSize?: int32(name='PageSize', example='50'),
  requestId?: string(name='RequestId', example='7863CA18-8FC6-5C21-BAF4-18C2A5700B94'),
  totalNumber?: int32(name='TotalNumber', example='10'),
}

model ListResourcesByTagResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListResourcesByTagResponseBody(name='body'),
}

async function listResourcesByTagWithOptions(request: ListResourcesByTagRequest, runtime: Util.RuntimeOptions): ListResourcesByTagResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.tagKeys)) {
    query['TagKeys'] = request.tagKeys;
  }
  if (!Util.isUnset(request.tagValues)) {
    query['TagValues'] = request.tagValues;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListResourcesByTag',
    version = '2023-02-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function listResourcesByTag(request: ListResourcesByTagRequest): ListResourcesByTagResponse {
  var runtime = new Util.RuntimeOptions{};
  return listResourcesByTagWithOptions(request, runtime);
}

model ListTagsAllResponseBody = {
  data?: string(name='Data', example='{
    "key1": [
      "value1",
      "value2"
    ],
    "key2": [
      "value3"
    ],
    "key3": [
      "value4"
    ]
  }'),
  requestId?: string(name='RequestId', example='F1A0FF6B-4875-5573-A541-897B738C5325'),
}

model ListTagsAllResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListTagsAllResponseBody(name='body'),
}

async function listTagsAllWithOptions(runtime: Util.RuntimeOptions): ListTagsAllResponse {
  var req = new OpenApi.OpenApiRequest{};
  var params = new OpenApi.Params{
    action = 'ListTagsAll',
    version = '2023-02-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function listTagsAll(): ListTagsAllResponse {
  var runtime = new Util.RuntimeOptions{};
  return listTagsAllWithOptions(runtime);
}

model ListTagsByResourceRequest {
  resourceIds?: [ string ](name='ResourceIds'),
}

model ListTagsByResourceResponseBody = {
  data?: string(name='Data', example='{
    "rm-xxxxxx1":
    {
        "Product": "Rds",
        "owner": "zhangsan",
        "env": "daily"
    }
}'),
  requestId?: string(name='RequestId', example='DE3EC85A-3950-5A82-A1CC-4E5462FF60E0'),
}

model ListTagsByResourceResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListTagsByResourceResponseBody(name='body'),
}

async function listTagsByResourceWithOptions(request: ListTagsByResourceRequest, runtime: Util.RuntimeOptions): ListTagsByResourceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.resourceIds)) {
    query['ResourceIds'] = request.resourceIds;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListTagsByResource',
    version = '2023-02-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function listTagsByResource(request: ListTagsByResourceRequest): ListTagsByResourceResponse {
  var runtime = new Util.RuntimeOptions{};
  return listTagsByResourceWithOptions(request, runtime);
}

model MetaDatabaseSearchRequest {
  limit?: long(name='Limit', example='20'),
  searchKey?: string(name='SearchKey', example='test'),
  start?: long(name='Start', example='0'),
}

model MetaDatabaseSearchResponseBody = {
  code?: string(name='Code', example='BizError'),
  data?: string(name='Data', example='{
    "searchResult": [
      {
        "dbState": 0,
        "ipPortSid": "rds:mysql:rdsmysql",
        "dbType": 8,
        "idc": "cn-hangzhou",
        "schemaName": "test",
        "sid": "",
        "catalogName": "test2",
        "instanceId": 1432432***,
        "instanceState": 0,
        "port": 3306,
        "dbId": 4324***,
        "searchName": "test@rdsmysql.com:3306 [test]",
        "tenantId": 421423***,
        "host": "rdsmysql.com",
        "instanceResourceId": "rdsmysql",
        "alias": "test"
      }
    ],
    "searchTime": 0.014801,
    "searchTotalNum": 2
  }'),
  message?: string(name='Message', example='BizError'),
  requestId?: string(name='RequestId', example='657E03FC-3A29-5790-A66C-F0B7F7729E8F'),
  success?: boolean(name='Success', example='true'),
}

model MetaDatabaseSearchResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: MetaDatabaseSearchResponseBody(name='body'),
}

async function metaDatabaseSearchWithOptions(request: MetaDatabaseSearchRequest, runtime: Util.RuntimeOptions): MetaDatabaseSearchResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.limit)) {
    query['Limit'] = request.limit;
  }
  if (!Util.isUnset(request.searchKey)) {
    query['SearchKey'] = request.searchKey;
  }
  if (!Util.isUnset(request.start)) {
    query['Start'] = request.start;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'MetaDatabaseSearch',
    version = '2023-02-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function metaDatabaseSearch(request: MetaDatabaseSearchRequest): MetaDatabaseSearchResponse {
  var runtime = new Util.RuntimeOptions{};
  return metaDatabaseSearchWithOptions(request, runtime);
}

model MetaSearchRequest {
  limit?: long(name='Limit', example='20'),
  searchKey?: string(name='SearchKey', example='test'),
  start?: long(name='Start', example='0'),
}

model MetaSearchResponseBody = {
  code?: string(name='Code', example='BizError'),
  data?: string(name='Data', example='{
    "searchResult": [{
        "dbState": 0,
        "ipPortSid": "rds:mysql:rm-xxx",
        "dbType": 0,
        "idc": "cn-hangzhou",
        "schemaName": "test0913",
        "tableName": "__test_testeee",
        "sid": "",
        "catalogName": "def",
        "tableDescription": "testeee",
        "instanceId": 2103***,
        "instanceState": 0,
        "port": 3306,
        "dbId": 35714***,
        "searchName": "test0913@rm-xxx.mysql.rds.aliyuncs.com:3306 [rm-xxx]",
        "tenantId": 432532***,
        "host": "rm-xxx.mysql.rds.aliyuncs.com",
        "instanceResourceId": "rm-xxx",
        "tableId": 1021306***,
        "alias": "rm-bp1qp45785ab3r272"
    }],
    "searchTime": 0.05393,
    "searchTotalNum": 5000
}'),
  message?: string(name='Message', example='BizError'),
  requestId?: string(name='RequestId', example='17D76348-FD6B-5F95-B7B8-4AE9B6785B2B'),
  success?: boolean(name='Success', example='true'),
}

model MetaSearchResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: MetaSearchResponseBody(name='body'),
}

async function metaSearchWithOptions(request: MetaSearchRequest, runtime: Util.RuntimeOptions): MetaSearchResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.limit)) {
    query['Limit'] = request.limit;
  }
  if (!Util.isUnset(request.searchKey)) {
    query['SearchKey'] = request.searchKey;
  }
  if (!Util.isUnset(request.start)) {
    query['Start'] = request.start;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'MetaSearch',
    version = '2023-02-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function metaSearch(request: MetaSearchRequest): MetaSearchResponse {
  var runtime = new Util.RuntimeOptions{};
  return metaSearchWithOptions(request, runtime);
}

model UpdateUserAuthRequest {
  grantState?: long(name='GrantState', example='1'),
}

model UpdateUserAuthResponseBody = {
  code?: string(name='Code', example='BizError'),
  data?: string(name='Data', example='{\\"authState\\": 1, \\"lastAuthDate\\": \\"2023-04-13T06:26:39.574+00:00\\"}'),
  message?: string(name='Message', example='BizError'),
  requestId?: string(name='RequestId', example='A4827539-ABEC-5889-B7BF-E83FC98344D3'),
  success?: boolean(name='Success', example='true'),
}

model UpdateUserAuthResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: UpdateUserAuthResponseBody(name='body'),
}

async function updateUserAuthWithOptions(request: UpdateUserAuthRequest, runtime: Util.RuntimeOptions): UpdateUserAuthResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.grantState)) {
    query['GrantState'] = request.grantState;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'UpdateUserAuth',
    version = '2023-02-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function updateUserAuth(request: UpdateUserAuthRequest): UpdateUserAuthResponse {
  var runtime = new Util.RuntimeOptions{};
  return updateUserAuthWithOptions(request, runtime);
}

model YaochiSuggestRequest {
  suggestText?: string(name='SuggestText', example='test'),
}

model YaochiSuggestResponseBody = {
  code?: string(name='Code', example='BizError'),
  data?: string(name='Data', example='true'),
  message?: string(name='Message', example='BizError'),
  requestId?: string(name='RequestId', example='7B51D0CE-41F7-578D-BA67-5754919117F6'),
  success?: boolean(name='Success', example='true'),
}

model YaochiSuggestResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: YaochiSuggestResponseBody(name='body'),
}

async function yaochiSuggestWithOptions(request: YaochiSuggestRequest, runtime: Util.RuntimeOptions): YaochiSuggestResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.suggestText)) {
    query['SuggestText'] = request.suggestText;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'YaochiSuggest',
    version = '2023-02-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function yaochiSuggest(request: YaochiSuggestRequest): YaochiSuggestResponse {
  var runtime = new Util.RuntimeOptions{};
  return yaochiSuggestWithOptions(request, runtime);
}

